package com.x.erp.service;

import com.x.erp.manage.NoticeManage;
import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.NoticeDao;
import com.x.erp.model.Notice;
import com.x.erp.model.NoticeMarket;
import com.x.erp.rpc.NoticeRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Service(interfaceName = "com.x.erp.rpc.NoticeRpcService", timeout = 60000)
public class NoticeService extends BaseService implements NoticeRpcService {

	@Autowired
	private NoticeDao noticeDao;

	@Autowired
	private NoticeManage noticeManage;

	@Override
	public List<Notice> selectNoticeList(Notice notice) {
		try {
			return noticeDao.selectNoticeList(notice);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public int selectNoticeNum(Notice notice) {
		try {
			return noticeDao.selectNoticeNum(notice);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public int selectNoticeListNum(NoticeMarket noticeMarket) {
		try {
			return noticeDao.selectNoticeListNum(noticeMarket);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public int selectNoticeMarketNum(NoticeMarket noticeMarket) {
		try {
			return noticeDao.selectNoticeMarketNum(noticeMarket);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0009, e);
		}
	}

	@Override
	public Notice insertNotice(Notice notice, String marketId) {
		try {
			return noticeManage.insertNotice(notice, marketId);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public void updateNotice(Notice notice, String marketId) {
		try {
			noticeManage.updateNotice(notice, marketId);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public List<NoticeMarket> selectNoticeMarketList(NoticeMarket noticeMarket) {
		try {
			return noticeDao.selectNoticeMarketList(noticeMarket);
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

	@Override
	public Integer updateNotice(Notice notice) {
		try {
			notice.setNoticeUpdateTime(this.getDate(0));
			int update = this.update(notice);
			return update;
		} catch (Exception e) {
			throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
		}
	}

}
